package net.nohaven.proj.javeau.utils;

public class BitArrayInputStream {
	private int[] bitArray;
	private int idx;

	public BitArrayInputStream(byte[] array) {
		int[] tmpArray = new int[array.length * 8];
		for (int i = 0; i < array.length; i++)
			for (int j = 7; j >= 0; j--) {
				tmpArray[i * 8 + j] = array[i] & 1;
				array[i] >>= 1;
			}

		//strip padding
		int i = tmpArray.length - 1;
		while (tmpArray[i] == 0)
			i--;
		bitArray = new int[i];
		System.arraycopy(tmpArray, 0, bitArray, 0, i);

		idx = 0;
	}

	public int getBit() {
		if (idx == bitArray.length)
			return -1;
		return bitArray[idx++];
	}
}
